import pandas as pd
import numpy as np
from sklearn.preprocessing import StandardScaler, MinMaxScaler

# 创建示例 DataFrame
data = {
    'Name': ['Alice', 'Bob', 'Charlie', 'David', 'Eva'],
    'Age': [25, 30, np.nan, 35, 40],
    'Score': [88, np.nan, 85, 79, 90],
    'Date': ['2021-01-01', '2022-02-15', '2023-03-30', '2021-12-01', '2022-05-20']
}
df = pd.DataFrame(data)

# 字符串处理
df['Name'] = df['Name'].str.lower()  # 转换为小写
print(df)
print('===========字符串处理示例代码===========')

# 时间戳转换
df['Date'] = pd.to_datetime(df['Date'])
print(df)
print('===========时间戳转换示例代码===========')

# 提取日期特征
df['Year'] = df['Date'].dt.year
df['Month'] = df['Date'].dt.month
print(df)
print('===========提取日期特征示例代码===========')

# 日期差异计算
df['Start_Date'] = pd.to_datetime(['2021-01-01', '2022-02-15', '2023-03-30', '2021-12-01', '2022-05-20'])
df['End_Date'] = pd.to_datetime(['2022-01-01', '2023-02-15', '2024-03-30', '2022-12-01', '2023-05-20'])
df['Date_Diff'] = df['End_Date'] - df['Start_Date']
print(df)
print('===========日期差异计算示例代码===========')